﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Domain.MainModule.Entities;
using Infraestructure.Data.MainModule.UnitOfWork;
using Infraestructure.CrossCutting.Logging;
using Domain.MainModule.Cities;
using Infraestructure.Data.MainModule.Repositories;

namespace Infraestructure.Data.MainModule.Tests.RepositoriesTests
{
    [TestClass()]
    public class CityRepositoryTest : RepositoryTestsBase<City>
    {
       string cityName = "Balcarce";
       
       public override System.Linq.Expressions.Expression<Func<City, bool>> FilterExpression
        {
            get { return a => a.Name == cityName; }
        }

        public override System.Linq.Expressions.Expression<Func<City, Guid>> OrderByExpression
        {
            get { return a => a.CityId; }
        }
		
		[TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void FindCity_Invoke_NullSpecThrowNewArgumentNullException_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            ICityRepository repository = new CityRepository(context,traceManager);

            //Act
            repository.FindCity(null);
        }
			
		[TestMethod()]
        public void FindCity_Invoke_InvalidCityNameReturnNullObject_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            ICityRepository repository = new CityRepository(context, traceManager);

			string invalidCityName = "Felicidonia";
            CityNameSpecification spec = new CityNameSpecification(invalidCityName);

            //Act
            City xentity = repository.FindCity(spec);

            //Assert
            Assert.IsNull(xentity);
        }
		
        [TestMethod()]
        public void FindCityById_Invoke_Test()
        {
            //Arrange 
            IMainModuleUnitOfWork context = GetUnitOfWork();
            ITraceManager traceManager = this.GetTraceManager();
            ICityRepository repository = new CityRepository(context, traceManager);

            CityNameSpecification spec = new CityNameSpecification(cityName);

            //Act
            City city = repository.FindCity(spec);

            //Assert
            Assert.IsNotNull(city);
        }
    }
}
